package com.frank.jpaSpecification.controller;

import com.frank.jpaSpecification.entity.PageStudentRequest;
import com.frank.jpaSpecification.entity.Student1;
import com.frank.jpaSpecification.repository.StudentRepository;
import com.frank.jpaSpecification.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * @author 小石潭记
 * @date 2020/12/12 19:02
 * @Description: ${todo}
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private StudentRepository studentRepository;

    @GetMapping
    public Page<Student1> index(PageStudentRequest pageStudentRequest) {
        return studentService.getStudentList(pageStudentRequest);
    }

    @GetMapping("/test")
    public void test(PageStudentRequest pageStudentRequest) {
        List<Student1> all = studentRepository.findAll();
        studentService.handleStudents(all);
    }

    @GetMapping("/get")
    public Student1 get() {
        /*Optional<Student1> byMobile = studentRepository.findByMobile("17380498226");
        byMobile.get().setAge(996);
        studentRepository.save(byMobile.get());
        return byMobile.get();*/
        return studentRepository.findByMobile("17380498226").get();
    }

}
